<!DOCTYPE html>
<html>

<head>
    <title>攻略列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>

</head>
<script type="text/javascript">
    var user = JSON.parse(sessionStorage.getItem("user"));
    $(function () {
        var user = JSON.parse(sessionStorage.getItem("user"));
        $.get("/users/"+user.id+"/collects/strategies",function (data) {
            if(data.length<=0){
                $(document).dialog({
                    type : 'confirm',
                    closeBtnShow: true,
                    content: '您还没有收藏的游记哦！马上去收藏！',
                    onClickConfirmBtn: function(){
                        window.location.href="/strategyPage.html";
                    },
                    onClickCancelBtn : function(){
                    },
                    onClickCloseBtn  : function(){
                    }
                });
                $(".collects").html("");
                return;
            }else{
                $(".collects").renderValues({list:data},{
                    link:function (ele,value) {
                        ele.href ="/strategyCatalogs.html?strategyId="+value;
                    }
                });
            }
        })
    })

    //取消收藏方法
    function cancle(obj) {
        var id = $(obj).find("span").data("id");
        $(document).dialog({
            type : 'confirm',
            closeBtnShow: true,
            content: '确定要取消收藏吗？',
            onClickConfirmBtn: function(){
                $.post("/collects/users/delete", {type: 1, collectId: id, userId: user.id}, function (data) {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '取消收藏成功',//提示
                        autoClose: 2500,//xx秒后自动消失
                        position: 'center'  // center: 居中; bottom: 底部
                    });
                    window.location.reload();
                })
            },
            onClickCancelBtn : function(){

            },
            onClickCloseBtn  : function(){
            }
        });
    }
</script>
<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left" ></i></span>
            </a>
        </div>
        <div class="col">
            <span>我收藏的攻略</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="container collects">
    <p>
    </p>
    <div id="allTravels" render-loop="list">
        <div class="row detail">
            <div class="col">
                <a render-key="list.id" render-fun="link">
                    <h5 render-html="list.title"></h5>
                </a>
                <span render-html="list.collects"></span> </a><span>人已收藏</span> </a>
                <p>
                </p>
                <p>
                    <a href="javascript:;" onClick="cancle(this)">
                        <i class="fa fa-heart" ><span render-attr="data-id=list.id">取消收藏</span></i>
                    </a>
                </p>
            </div>
            <div class="col bigimg">
                <a render-key="list.id" render-fun="link">
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
    </div>
</div>

</body>

</html>